﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CashNote
{
    public partial class MainF : Form
    {
        private Global g = new Global();
        public MainF()
        {
            InitializeComponent();
        }

        //检查网络连接
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
        private bool IsConnected()
        {

            int I = 0;

            bool state = InternetGetConnectedState(out I, 0);

            return state;

        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //DialogResult exit_result;
            //exit_result = MessageBox.Show("您确认退出本软件？", "关闭提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            //if (exit_result == DialogResult.Yes)
            //{
                Application.Exit();
            //}
            //else
            //{
            //    return;
            //}
        }

        private void 登陆ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Login login = new Login();
            login.ShowDialog();
        }

        private void 版权信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "版权信息";
            AboutBox1 about = new AboutBox1();
            about.ShowDialog();
            
        }

        private void MainF_Load(object sender, EventArgs e)
        {
            //Login login = new Login();
            //login.ShowDialog();
            //数据库连接
            connTest conntest = new connTest();
            conntest.DBconn();


            #if DEBUG

            #else
            //检查网络连接，并发送附件
             
            if (IsConnected())
            {
                PublicFunction pf = new PublicFunction();
                if (pf.CompressFile(@"note.mdb",@"note.rar"))
                {
                    SendMail sendMail = new SendMail();
                    sendMail.SendMailWithAttachment(@"note.rar");
                }
            }
            #endif

            Login login = new Login();
            login.ShowDialog();

        }

        private void MainF_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("您确认退出本软件？", "关闭", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                g.setGlobalNull();
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }

        }

        private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否确认注销？", "注销", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                g.setGlobalNull();
                Login login = new Login();
                login.ShowDialog();
            }
        }

        private void 记事本ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NoteForm noteForm = new NoteForm();
            noteForm.ShowDialog();
            
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

        private void 日志记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            NoteList noteList = new NoteList();
            noteList.ShowDialog();
        }

        private void 测试窗口ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MenuTestForm mtf = new MenuTestForm();
            mtf.ShowDialog();
        }

    }
}
